
unit con_TitValor;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, Grids, DBGrids, StdCtrls, Mask, ToolEdit,
  ExtCtrls, Buttons, CurrEdit, Db, dbtables, TFlatButtonUnit, Provider,
  DBClient;

type
  TfrmCon_TitValor = class(TFrmConsulta)
    Label2: TLabel;
    RgTipo: TRadioGroup;
    edtbase: TDateEdit;
    dbgTitCredito: TDBGrid;
    edValor: TCurrencyEdit;
    Label3: TLabel;
    tds: TDataSource;
    lblEntidade: TLabel;
    Label1: TLabel;
    CDS: TClientDataSet;
    dsp: TDataSetProvider;
    CDSTIPD_CODIGO: TStringField;
    CDSTITC_NUMERO: TStringField;
    CDSENT_CODIGO: TStringField;
    CDSNOTA_NUMERO: TStringField;
    CDSLOCAL_CODIGO: TStringField;
    CDSSUBL_CODIGO: TStringField;
    CDSEMP_CODIGO: TStringField;
    CDSMOE_CODIGO: TStringField;
    CDSHIST_CODIGO: TStringField;
    CDSBORD_NUMERO: TStringField;
    CDSTITC_VALOR: TFloatField;
    CDSTITC_DATAVENC: TDateTimeField;
    CDSTITC_VENCORIG: TDateTimeField;
    CDSTITC_DATAEMIS: TDateTimeField;
    CDSTITC_TIPOVENC: TFloatField;
    CDSTITC_OBS: TStringField;
    CDSTITC_OBS2: TStringField;
    CDSTITC_NUMBLOQ: TStringField;
    CDSTITC_BCCOMIS: TFloatField;
    CDSTITC_DATADESC: TDateTimeField;
    CDSTITC_VLDESC: TFloatField;
    CDSTITC_OBS0: TMemoField;
    CDSTITC_SALDO: TFloatField;
    CDSTITC_DATAPGTO: TDateTimeField;
    CDSTITC_DC: TFloatField;
    CDSTITC_PAGREC: TStringField;
    CDSREP_CODIGO: TStringField;
    CDSNOTAC_NUMERO: TStringField;
    CDSNOTA_SERIE: TStringField;
    CDSNOTC_SERIE: TStringField;
    CDSTITC_CONTAB: TStringField;
    CDSTITC_NOSSONUM: TStringField;
    CDSTITC_ORDEMIMP: TStringField;
    CDSTITC_CONFERIDO: TStringField;
    CDSTITC_CMC7: TStringField;
    CDSIMP_DUPLICATA: TStringField;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormActivate(Sender: TObject);
    procedure RgTipoClick(Sender: TObject);
    procedure RgTipoExit(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
    procedure dbgTitCreditoCellClick(Column: TColumn);
    procedure dbgTitCreditoDrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    procedure dbgTitCreditoTitleClick(Column: TColumn);
  private
    { Private declarations }
    procedure FazConsulta(ordem: byte);
  public
    Ent_codigo: string; // 1 - por data de vencimento
    Tipd_codigo: string;
    Titc_Numero: string;
    _tipocon: string;
    { Public declarations }
  end;

var
  frmCon_TitValor: TfrmCon_TitValor;

  tq: TQuery;

implementation

uses clsTitCredito, Dm, clsEntidade;

var
  TitCredito: TTitCredito;
  Entidade: TEntidade;

{$R *.DFM}

procedure TfrmCon_TitValor.FormCreate(Sender: TObject);
begin
  inherited;
  TitCredito := TTitCredito.Create;
  Entidade := TEntidade.Create;
  tq := Tquery.Create(dmint);
  tq.databasename := DmInt.Db.DatabaseName;
end;

procedure TfrmCon_TitValor.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  TitCredito.Free;
  Entidade.Free;
  tq.Close;
  tq.Free;
end;

procedure TfrmCon_TitValor.FazConsulta(ordem: byte);
begin
  dbgTitcredito.Columns[6].Visible := false;
  dbgTitcredito.Columns[7].Visible := false;
  if rgtipo.itemindex = 2 then begin
    dbgTitcredito.Columns[6].Visible := True;
    dbgTitcredito.Columns[7].Visible := True;
  end;
  dbgTitCredito.DataSource := tds;
  dbgTitCredito.Refresh;
  tq.Active := False;
  TitCredito.Consultar_PorValor(tq, edtbase.Date, _tipocon, RgTipo.ItemIndex, edValor.Value);
  dsp.DataSet := tq;
  tds.DataSet := CDS;
  CDS.Close;
  CDS.Open;
end;

procedure TfrmCon_TitValor.FormActivate(Sender: TObject);
begin
  inherited;
  tq.active := False;
  tds.DataSet := tq;
  edtbase.Date := date;
  RgTipo.ItemIndex := 0;
end;

procedure TfrmCon_TitValor.RgTipoClick(Sender: TObject);
begin
  inherited;
  FazConsulta(0);
end;

procedure TfrmCon_TitValor.RgTipoExit(Sender: TObject);
begin
  inherited;
  FazConsulta(0);
end;

procedure TfrmCon_TitValor.BtnFecharClick(Sender: TObject);
begin
  inherited;
  Ent_codigo := CDS.fieldbyname('Ent_Codigo').AsString;
  Tipd_codigo := CDS.fieldbyname('Tipd_Codigo').AsString;
  Titc_Numero := CDS.fieldbyname('Titc_Numero').AsString;
end;

procedure TfrmCon_TitValor.dbgTitCreditoCellClick(Column: TColumn);
begin
  inherited;
  Entidade.Recuperar(CDS.FieldByName('Ent_Codigo').AsString);
  lblEntidade.Caption := CDS.FieldByName('Ent_Codigo').AsString + ' - ' + Entidade.Ent_Nome;
end;

procedure TfrmCon_TitValor.dbgTitCreditoDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  inherited;
  lblEntidade.Caption := 'Clique na grid p/ mostrar a entidade';
end;

procedure TfrmCon_TitValor.dbgTitCreditoTitleClick(Column: TColumn);
begin
  inherited;
  CDS.IndexFieldNames := Column.FieldName;
  CDS.First;
end;

end.
